define([
    'standalone',
    'parser-babylon',
    'parser-yaml',
    'parser-postcss',
    'parser-html',
    'parser-typescript'
], function(prettier, babylonPlugins, yamlPlugins, postcssPlugins, htmlPlugins, typescriptPlugins) {
    var prettierFactory = angular.module('app.factory.prettier', []);

    prettierFactory.factory('xPrettier', function() {
        const prettierPlugins = {
            'babylon': babylonPlugins,
            'yaml': yamlPlugins,
            'postcss': postcssPlugins,
            'html': htmlPlugins,
            'typescript': typescriptPlugins
        };

        var defaultOptions = {
            printWidth: 80,
            tabWidth: 4,
            useTabs: false,
            singleQuote: false,
            bracketSpacing: true,
            proseWrap: 'preserve',
            semi: true,
            jsxSingleQuote: false,
            jsxBracketSameLine: false,
            arrowParens: 'avoid',
            trailingComma: 'es5',
            htmlWhitespaceSensitivity: 'ignore',
            insertPragma: false,
            requirePragma: false,
            plugins: prettierPlugins
        };

        return {
            format: function(text, options) {
                return prettier.format(text, angular.extend(defaultOptions, options));
            }
        };
    });

    return prettierFactory;
});